home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-1 / icont.sit / mkkeytab.icn < prev    next >
Encoding:
Text File  |  1992-09-19  |  1.5 KB  |  49 lines  |  [TEXT/MPS ]

  1. # mkkeytab - builds keyword.c, which is structure of keywords and
  2. #  their identification numbers. also builds keyword.h, which has
  3. #  defined constants giving keyword identification numbers.
  4. #  input is list of keywords, (alphabetic order, one pair per line)
  5. #  in file "keywords.txt", elements of a pair are separated by one or more
  6. #  blanks or tabs.
  7.  
  8. procedure main(args)
  9. local df, f, input, word, atab, serial
  10.  
  11.    input := open("keywords.txt") | stop("unable to open \"keywords.txt\"")
  12.    f := open("keyword.c","w") | stop("unable to open \"keyword.c\"")
  13.    df := open("../h/keyword.h","w") | stop("unable to open \"keyword.h\"")
  14.    kf := open("../h/kdefs.h","w") | stop("unable to open \"kdefs.h\"")
  15.    write(df,"/*")
  16.    write(df," * Keyword manifest constants.")
  17.    write(df," */\n")
  18.  
  19.    write(kf,"/*")
  20.    write(kf," * Keyword definitions.")
  21.    write(kf," */\n")
  22.  
  23.    write(f, "#include \"../h/keyword.h\"")   # put out table header
  24.    write(f, "#include \"tsym.h\"")
  25.    write(f, "")
  26.    write(f, "/*")
  27.    write(f, " * Keyword table.")
  28.    write(f, " */")
  29.    write(f, "")
  30.    write(f, "struct keyent keytab[] = {")
  31.  
  32.    serial := 0
  33.    while word := read(input) do {
  34.       if not any(&lcase,word) then next
  35.       serial +:= 1
  36.       if *word < 6 then atab := "\t\t" else atab := "\t"
  37.       write(df, "#define K_",ucase(word),atab,right(serial,2)) 
  38.       write(kf, "KDef(",word,")")
  39.       write(f,"   \"",word,"\",\tK_",ucase(word),",")
  40.       }
  41.    write(f,"   \"\",\t\t-1")
  42.    write(f, "   };")
  43.  
  44. end
  45.  
  46. procedure ucase(name)
  47.    return map(name,&lcase,&ucase)
  48. end
  49.